package com.randi.monitor.dto;

import com.randi.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Transient;

@Data
@NoArgsConstructor
@ApiModel(value = "SysCache", description = "缓存信息")
public class SysCache {

    @ApiModelProperty(value = "缓存名称")
    private String cacheName;

    @ApiModelProperty(value = "缓存键名")
    private String cacheKey;

    @ApiModelProperty(value = "缓存键值")
    private Object cacheValue;

    @ApiModelProperty(value = "过期时间")
    private Long expire;

    @ApiModelProperty(value = "备注")
    private String remark;

    public SysCache(String cacheName, String remark) {
        this.cacheName = cacheName;
        this.remark = remark;
    }

    public SysCache(String cacheName, String cacheKey, String remark) {
        this.cacheName = cacheName;
        this.cacheKey = cacheKey;
        this.remark = remark;
    }

    @Transient
    public String getKey() {
        if (StringUtils.isNotEmpty(this.cacheKey)) {
            return this.cacheKey;
        }
        return this.cacheName;
    }

}
